function e(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}

e(require("../../../utils/filter"));

var a = e(require("../../../api/api")), t = e(require("../../../utils/util")), s = require("../../../config/constants"), o = getApp();

Page({
    data: {
        pageNum: 1,
        pageSize: 10,
        hasMore: !0,
        content_list: [],
        newMsg: "",
        errorMsg: !1
    },
    onLoad: function(e) {
        this.data.user_id = e.user_id, this.fetchMessageWithUser(e.user_id), this.pageScrollToBottom();
    },
    onReady: function() {
        this.pageScrollToBottom();
    },
    fetchMessageWithUser: function(e) {
        var t = this, s = this, o = {
            page: s.data.pageNum
        };
        a.default.messageWithUser({
            data: o,
            user_id: e,
            success: function(e) {
                var a = s.data.content_list;
                if (e && e.data) {
                    1 == s.data.pageNum && (a = []);
                    var o = e.data.data;
                    o.forEach(s.mergeMessageInfo), o.length < s.data.pageSize ? (t.setData({
                        content_list: a.concat(o),
                        hasMore: !1
                    }), console.log("-----", t.data.content_list)) : (t.setData({
                        content_list: a.concat(o),
                        hasMore: !0,
                        pageNum: s.data.pageNum + 1
                    }), console.log("=====", t.data.content_list));
                }
            }
        });
    },
    mergeMessageInfo: function(e) {
        e.avatar_file_name_url = s.CDN_ADDR + e.sender_obj.avatar_file_name + "_Avatar.jpg", 
        e.date_time_ago = t.default.dateTimeAgo(e.create_time);
    },
    onPullDownRefresh: function(e) {
        var a = this;
        a.data.hasMore && a.fetchMessageWithUser(user_id);
    },
    sendMsg: function(e) {
        var t = this, s = e.detail.value.textarea;
        if (t.setData({
            newMsg: s
        }), "" == s || s.length > 2e3) t.setData({
            errorMsg: !0
        }); else {
            t.setData({
                errorMsg: !1
            });
            var n = {
                content: s
            };
            a.default.messageWithUser({
                method: "POST",
                data: n,
                user_id: t.data.user_id,
                success: function(e) {
                    if (e && e.data.data) {
                        var a = {
                            sender_obj: {
                                avatar_file_name: o.globalData.userPersonalInfo.user_avatar_file,
                                allow_profile: o.globalData.userPersonalInfo.allow_profile,
                                nickname: o.globalData.userPersonalInfo.nickname,
                                id: o.globalData.userPersonalInfo.id
                            },
                            login_user_is_sender: 1,
                            type: 0,
                            create_time: e.data.data.create_time,
                            id: e.data.data.message_id,
                            message_id: e.data.data.message_id,
                            content: t.data.newMsg
                        };
                        t.data.content_list.push(a), t.data.content_list.forEach(t.mergeMessageInfo), t.setData({
                            content_list: t.data.content_list,
                            newMsg: ""
                        });
                    }
                }
            });
        }
    },
    pageScrollToBottom: function() {
        setTimeout(function() {
            wx.pageScrollTo({
                scrollTop: 1e4
            });
        }, 100);
    },
    onImageError: function(e) {
        var a = this;
        t.default.errImgFun(e, a);
    }
});